<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" session="false" %><%@
include file="/WEB-INF/jspf/import.jspf" %>
<!doctype HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<title>车友会升级</title>
<meta name="keywords" content="" />
<meta name="description" content="http://js.3conline.com/wap/pcauto/2014/" />
<meta name="author" content="wangcaixia_gz wuzehan" />
<link type="text/css" rel="stylesheet" href="http://js.3conline.com/bbs/cargroup/cargroupApp3/cyhsj.css" />
</head>
<body>
<c:if test="${isValid == 5}">
<div class="g-doc">
    <div class="m-hd">
        <p class="m-hd-tit">恭喜，您的车友会已达到${clubLevel.levelName}的要求！</p>
        <p class="m-hd-img">
            <span class="star${levelId}"></span>
            <!--星级对应样式：star1/star2/star3/star4/star5 -->
        </p>
        <div class="m-list">
            <p class="m-list-tit">${clubLevel.levelName}奖品清单：</p>
            
             <c:forEach items="${prizes}" var="data" varStatus="status">
                <div class="m-list-p">
                    <span>${status.count}</span>
                    <p>${data.prize}</p>
                </div>
             </c:forEach>
            
        </div>
    </div>

    <div class="m-bd">
        <div class="m-address">收货地址：</div>
        <div class="m-bd-sum">
            <div class="m-bd-div">
                <div class="m-bd-bord">
                    <span>收件人</span>
                    <p>
                        <input type="text" id="Jname" name="name" value="${awardRecord.name }" ${awardRecord.received==1?'disabled':''}/>
                    </p>
                </div>
                <i class="error">!&nbsp;请输入您的姓名</i>
            </div>

            <div class="m-bd-div">
                <div class="m-bd-bord">
                    <span>邮寄地址</span>
                    <p>
                        <input type="text" id="Jaddress" name="address" value="${awardRecord.address}" ${awardRecord.received==1?'disabled':''}/>
                    </p>
                </div>
                <i class="error">!&nbsp;请输入您的邮寄地址</i>
            </div>


            <div class="m-bd-div">
                <div class="m-bd-bord">
                    <span>邮编</span>
                    <p>
                        <input type="text" id="Jcode" name="postcode" value="${awardRecord.postalCode}" ${awardRecord.received==1?'disabled':''}/>
                    </p>
                </div>
                <i class="error">!&nbsp;请输入您的邮编</i>
            </div>

            <div class="m-bd-div">
                <div class="m-bd-bord">
                    <span>联系电话</span>
                    <p>
                        <input type="text" id="Jphone" name="phone" value="${awardRecord.phone}" ${awardRecord.received==1?'disabled':''}/>
                    </p>
                </div>
                <i class="error">!&nbsp;请输入您的联系电话</i>
            </div>
        </div>
    </div>

    <div class="m-up">
        <button class="btn-submit" onclick="ajaxSubmit()">立即升级</button>
    </div>
</div>
</c:if>

<!-- 遮罩层 -->
<div class="m-mask" id="Jmask"></div>
<!-- 遮罩层上的文字 -->
<div class="m-certify" id="Jcertify">
    <div class="m-success">升级成功</div>
    <div class="m-sccessTit">恭喜！您的车友会成功升级为${clubLevel.levelName}</div>
</div>

<script src="http://js.3conline.com/wap/2013/common/js/zepto.min.js" type="text/javascript"></script>
<script>
//for android app
window.onload = function(){
    if (${from=='android'} && ${noCookie==true}) {
        appCallback(getCookie("${userSessionName}"));
    }
};

function appCallback(_csid){
    writeCookie("${userSessionName}", _csid, 1);
}

function writeCookie(name,value,day){
    expire = "";
    expire = new Date();
    expire.setTime(expire.getTime()+day*24*3600*1000);
    expire = expire.toGMTString();
    document.cookie = name + "=" + escape(value) +"; path=/" + "; expires=" + expire;
    location.href = location.href;
}

function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]);
    return null;
};
//for android app end

var Jname = $('#Jname'),
    Jaddress = $('#Jaddress'),
    Jcode = $('#Jcode'),
    Jphone = $('#Jphone');
//提交
function ajaxSubmit(){
    var result = true,
        JnameVal = Jname.val(),
        JaddressVal = Jaddress.val(),
        JcodeVal = Jcode.val(),
        JphoneVal = Jphone.val();
    //<c:if test=" ${received!=1}/">
    //提交前再次验证
    if(!IsName(JnameVal)){result = false;}
    if(!IsAddress(JaddressVal)){result = false;}
    if(!IsCode(JcodeVal)){result = false;}
    if(!IsTelephone(JphoneVal)){result = false;}
    //</c:if>
    if (result) {
        // 校验成功后的表单提交
            $.ajax({
               type: "POST",
               url: "${fn:indexOf(WAPROOT, header.host)!=-1? WAPROOT : '/wap'}/club/updateClubLevel.do",
               data: {
                    levelId:${levelId},
                    clubId:${clubId},
                    name:JnameVal,
                    phone:JphoneVal,
                    address:JaddressVal,
                    postalCode:JcodeVal },
               success: function(data){
                    data = eval("("+data+")");
                    if(data.statusCode ==0){
                        var Jmask = $('#Jmask'),
                        Jcertify = $('#Jcertify');
                        Jmask.css('z-index','101').animate({opacity:'0.5'});
                        Jcertify.css('z-index','102').animate({opacity:'1'});
                        setTimeout(function(){
                            Jmask.animate({opacity:'0'});
                            Jcertify.animate({opacity:'0'});
                        },2000);
                        setTimeout(function(){
                            window.location.href="pcation://goback"; //提示升级成功后跳转的链接
                        },2000);
                    }else{
                        alert(data.message);
                    }
               }
            }); 
    } else {
        return false;
    }
}

//失焦验证
Jname.blur(function(){IsName(this.value)})
Jaddress.blur(function(){IsAddress(this.value)})
Jcode.blur(function(){IsCode(this.value)})
Jphone.blur(function(){IsTelephone(this.value)})

//正则验证收件人
function IsName(obj) {
    var reg = /^[\u4e00-\u9fa5a-zA-Z\s]{1,20}$/;
    var error0 = $('.error').eq(0);
    if($.trim(obj)==''){
        error0.html('!&nbsp;请输入您的姓名').css('display','block');
        return false;
    }
    else if (!reg.test($.trim(obj))) {
        error0.html('!&nbsp;姓名请使用中文或英文字符').css('display','block');
        return false;
    } else {
        error0.css('display','none');
        return true;
    }
}
//正则验证邮寄地址
function IsAddress(obj){
    var error1 = $('.error').eq(1);
    if($.trim(obj)==''){
        error1.css('display','block');
        return false;
    }else {
        error1.css('display','none');
        return true;
    }
}

//正则验证邮编
function IsCode(obj) {  
    var code = /^[0-9][0-9]{5}$/;
    var error2 = $('.error').eq(2);
    if($.trim(obj)==''){
        error2.html('!&nbsp;请输入您的邮编').css('display','block');
        return false;
    }
    else if (!code.test($.trim(obj))) {
        error2.html('!&nbsp;邮编格式错误').css('display','block');
        return false;
    } else {
        error2.css('display','none');
        return true;
    }  
} 

//正则验证联系电话
function IsTelephone(obj) {
    var pattern = /(^[0-9]{3,4}\-[0-9]{5,8}$)|(^0{0,1}1[0-9]{10}$)/;
    var error3 = $('.error').eq(3);
    if($.trim(obj)==''){
        error3.html('!&nbsp;请输入您的联系电话').css('display','block');
        return false;
    }
    else if (!pattern.test(obj)) {
        error3.html('!&nbsp;座机(020-xxxxxxx)/手机(1xxxxxxxxxx)').css('display','block');
        return false;
    } else {
        error3.css('display','none');
        return true;
    }
}

</script>
<%
Enumeration headerKeys = request.getHeaderNames();
while(headerKeys.hasMoreElements()) {
    String name = headerKeys.nextElement().toString();
    System.out.println(name + " = " + request.getHeader(name));
}
//${from=='android'} && ${noCookie}
System.out.println(request.getAttribute("from") + " && " + request.getAttribute("noCookie"));
%>
</body>
</html>